# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models


# Create your models here.


class FaultRecord(models.Model):
    RECORD_TYPE = ((0, "维保检查"), (1, "日常检查"), (2, "定期检查"))
    results = models.CharField(verbose_name='检查结果', max_length=100)
    remarks = models.CharField(verbose_name='备注', max_length=500, null=True, blank=True)
    type = models.IntegerField(verbose_name='检查类型', choices=RECORD_TYPE, default=RECORD_TYPE[0])
    status = models.BooleanField(verbose_name='状态', default=True)
    create_date = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_date = models.DateTimeField(verbose_name='修改时间', auto_now=True)

    class Meta:
        db_table = 't_fault_record'
        verbose_name = "故障记录"
        verbose_name_plural = "故障记录"
        permissions = (
            ("add_fault", u"新增故障记录"),
            ("change_fault", u"修改故障记录"),
            ("delete_fault", u"删除故障记录"),
        )

    def __str__(self):
        return self.name


class FaultRecordImg(models.Model):
    fault_record = models.ForeignKey(FaultRecord, verbose_name='故障记录', null=True, blank=True)
    name = models.CharField(verbose_name='文件名', max_length=30)
    desc = models.CharField(verbose_name='文件备注', max_length=100, null=True, blank=True)
    url = models.CharField(verbose_name='url地址', max_length=500, null=True, blank=True)
    path = models.CharField(verbose_name='文件路径', max_length=500, null=True, blank=True)
    status = models.BooleanField(verbose_name='状态', default=True)
    create_date = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    update_date = models.DateTimeField(verbose_name='修改时间', auto_now=True)

    class Meta:
        db_table = 't_fault_record_img'
        verbose_name = "故障照片"
        verbose_name_plural = "故障照片"

    def __str__(self):
        return self.name
